package com.aopcinemas.visitor.ui;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.text.SimpleDateFormat;

import javax.swing.JComboBox;
import javax.swing.JFormattedTextField;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import com.aopcinemas.cinema.model.Movie.AgeConstraint;
import com.aopcinemas.cinema.model.Movie.Genre;
import com.toedter.calendar.JDateChooser;

public class MovieSearchPanel extends JPanel {

    private static final long serialVersionUID = 1L;

    GridBagLayout layout = new GridBagLayout();
    GridBagConstraints constraints = new GridBagConstraints();

    JDateChooser startDate = new JDateChooser();
    JFormattedTextField startTime = new JFormattedTextField(new SimpleDateFormat("HH:mm"));
    JDateChooser endDate = new JDateChooser();
    JFormattedTextField endTime = new JFormattedTextField(new SimpleDateFormat("HH:mm"));
    JTextField movieName = new JTextField(10);
    JComboBox genreList = new JComboBox(Genre.values());
    JComboBox ageConstraintList = new JComboBox(AgeConstraint.values());
    JTextField period = new JTextField(10);

    public MovieSearchPanel() {

        constraints.insets = new Insets(3, 3, 3, 3);
        setLayout(layout);

        JLabel label = new JLabel("From: ");
        constraints.anchor = GridBagConstraints.EAST;
        constraints.gridwidth = 1;
        layout.setConstraints(label, constraints);
        add(label);

        constraints.anchor = GridBagConstraints.WEST;
        constraints.gridwidth = 1;
        layout.setConstraints(startTime, constraints);
        startTime.setColumns(10);
        add(startTime);

        constraints.gridwidth = GridBagConstraints.REMAINDER;
        layout.setConstraints(startDate, constraints);
        add(startDate);

        label = new JLabel("To: ");
        constraints.gridwidth = 1;
        constraints.anchor = GridBagConstraints.EAST;
        layout.setConstraints(label, constraints);
        add(label);

        constraints.gridwidth = 1;
        constraints.anchor = GridBagConstraints.WEST;
        layout.setConstraints(endTime, constraints);
        endTime.setColumns(10);
        add(endTime);

        constraints.gridwidth = GridBagConstraints.REMAINDER;
        layout.setConstraints(endDate, constraints);
        add(endDate);

        label = new JLabel("Movie name: ");
        constraints.gridwidth = 1;
        constraints.anchor = GridBagConstraints.EAST;
        layout.setConstraints(label, constraints);
        add(label);

        constraints.gridwidth = GridBagConstraints.REMAINDER;
        constraints.anchor = GridBagConstraints.WEST;
        layout.setConstraints(movieName, constraints);
        add(movieName);

        label = new JLabel("Genre: ");
        constraints.gridwidth = 1;
        constraints.anchor = GridBagConstraints.EAST;
        layout.setConstraints(label, constraints);
        add(label);

        constraints.gridwidth = GridBagConstraints.REMAINDER;
        constraints.anchor = GridBagConstraints.WEST;
        layout.setConstraints(genreList, constraints);
        add(genreList);

        label = new JLabel("Age constraint: ");
        constraints.gridwidth = 1;
        constraints.anchor = GridBagConstraints.EAST;
        layout.setConstraints(label, constraints);
        add(label);

        constraints.gridwidth = GridBagConstraints.REMAINDER;
        constraints.anchor = GridBagConstraints.WEST;
        layout.setConstraints(ageConstraintList, constraints);
        add(ageConstraintList);

        label = new JLabel("Notification period: ");
        constraints.gridwidth = 1;
        constraints.anchor = GridBagConstraints.EAST;
        layout.setConstraints(label, constraints);
        add(label);

        constraints.gridwidth = GridBagConstraints.REMAINDER;
        constraints.anchor = GridBagConstraints.WEST;
        layout.setConstraints(period, constraints);
        add(period);
    }
}
